package com.enrollandpay.service;

import com.enrollandpay.dao.ActivityMapper;
import com.enrollandpay.base.BaseService;
import com.enrollandpay.model.Activity;
import com.enrollandpay.utils.CommonUtil;
import com.enrollandpay.utils.ResultJson;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.beans.Transient;
import java.util.List;

/**
 * Created by 94504 on 2017/6/23.
 */
@Service
public class ActivityService extends BaseService<Activity, ActivityMapper>
{
    @Autowired
    private ActivityMapper activityMapper;

    /**
     * 保存操作
     *
     * @param activity
     */
    @Transactional
    public void save(Activity activity)
    {
        if (activity != null && activity.getId() != null)
            activityMapper.updateByPrimaryKeySelective(activity);
        else
            activityMapper.insert(activity);
    }

    /**
     * 根据复数的id来删除对应的数据
     * @param param
     *      按separatorChar拼接的id
     * @param separatorChar
     *      分割符
     * @return ResultJson
     *      ResultJson.status == 0 有错误 ，否则表示成功
     */
    public ResultJson deleteByIds(String param, Character separatorChar)
    {
        ResultJson resultJson = new ResultJson();
        Integer[] ids = CommonUtil.stringToIntegerArr(param, separatorChar);
        if (ids != null)
        {
            for (Integer id : ids)
                activityMapper.deleteByPrimaryKey(id);

            return resultJson;
        }

        resultJson.setStatus("0");
        return resultJson;

    }


}
